﻿using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
namespace Frame.DataHelper
{
    abstract class SqlHelper
    {
        // 存贮Cache缓存的Hashtable集合

        private static Hashtable parmCache = Hashtable.Synchronized(new Hashtable());

        /// <summary>
        /// 使用连接字符串，执行一个SqlCommand命令（没有记录返回）
        /// 使用提供的参数集.
        /// </summary>
        /// <remarks>
        /// 示例:  
        ///  int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="connectionString">一个有效的SqlConnection连接串</param>
        /// <param name="cmdType">命令类型CommandType(stored procedure, text, etc.)</param>
        /// <param name="cmdText">存贮过程名称或是一个T-SQL语句串</param>
        /// <param name="commandParameters">执行命令的参数集</param>
        /// <returns>受此命令影响的行数</returns>
        public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            SqlCommand cmd = new SqlCommand();
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
                int val = cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
                return val;
            }
        }

        /// <summary>
        /// 在一个存在的连接上执行数据库的命令操作
        /// 使用提供的参数集.
        /// </summary>
        /// <remarks>
        /// e.g.:  
        ///  int result = ExecuteNonQuery(connection, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="connection">一个存在的数据库连接对象</param>
        /// <param name="cmdType">命令类型CommandType (stored procedure, text, etc.)</param>
        /// <param name="cmdText">存贮过程名称或是一个T-SQL语句串</param>
        /// <param name="commandParameters">执行命令的参数集</param>
        /// <returns>受此命令影响的行数</returns>
        public static int ExecuteNonQuery(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            SqlCommand cmd = new SqlCommand();
            PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
            int val = cmd.ExecuteNonQuery();
            cmd.Parameters.Clear();
            return val;
        }

        /// <summary>
        /// 在一个事务的连接上执行数据库的命令操作
        /// 使用提供的参数集.
        /// </summary>
        /// <remarks>
        /// e.g.:  
        ///  int result = ExecuteNonQuery(trans, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="trans">一个存在的事务</param>
        /// <param name="cmdType">命令类型CommandType (stored procedure, text, etc.)</param>
        /// <param name="cmdText">存贮过程名称或是一个T-SQL语句串</param>
        /// <param name="commandParameters">执行命令的参数集</param>
        /// <returns>受此命令影响的行数</returns>
        public static int ExecuteNonQuery(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            SqlCommand cmd = new SqlCommand();
            PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, commandParameters);
            int val = cmd.ExecuteNonQuery();
            cmd.Parameters.Clear();
            return val;
        }

        /// <summary>
        /// 在一个连接串上执行一个命令，返回一个SqlDataReader对象
        /// 使用提供的参数.
        /// </summary>
        /// <remarks>
        /// e.g.:  
        ///  SqlDataReader r = ExecuteReader(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="connectionString">一个有效的SqlConnection连接串</param>
        /// <param name="cmdType">命令类型CommandType(stored procedure, text, etc.)</param>
        /// <param name="cmdText">存贮过程名称或是一个T-SQL语句串</param>
        /// <param name="commandParameters">执行命令的参数集</param>
        /// <returns>一个结果集对象SqlDataReader</returns>
        public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            SqlCommand cmd = new SqlCommand();
            SqlConnection conn = new SqlConnection(connectionString);
            // 如果不存在要查询的对象，则发生异常
            // 连接要关闭
            // CommandBehavior.CloseConnection在异常时不发生作用
            try
            {
                PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                cmd.Parameters.Clear();
                return rdr;
            }
            catch
            {
                conn.Close();
                throw;
            }
        }

        /// <summary>
        /// 在一个连接串上执行一个命令，返回表中第一行，第一列的值
        /// 使用提供的参数.
        /// </summary>
        /// <remarks>
        /// e.g.:  
        ///  Object obj = ExecuteScalar(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="connectionString">一个有效的SqlConnection连接串</param>
        /// <param name="cmdType">命令类型CommandType(stored procedure, text, etc.)</param>
        /// <param name="cmdText">存贮过程名称或是一个T-SQL语句串</param>
        /// <param name="commandParameters">执行命令的参数集</param>        /// <returns>返回的对象，在使用时记得类型转换</returns>
        public static object ExecuteScalar(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            SqlCommand cmd = new SqlCommand();
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
                object val = cmd.ExecuteScalar();
                cmd.Parameters.Clear();
                return val;
            }
        }

        /// <summary>
        /// 在一个连接上执行一个命令，返回表中第一行，第一列的值
        /// 使用提供的参数.
        /// </summary>
        /// <remarks>
        /// e.g.:  
        ///  Object obj = ExecuteScalar(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="connection">一个有效的SqlConnection连接</param>
        /// <param name="cmdType">命令类型CommandType(stored procedure, text, etc.)</param>
        /// <param name="cmdText">存贮过程名称或是一个T-SQL语句串</param>
        /// <param name="commandParameters">执行命令的参数集</param>        /// <returns>返回的对象，在使用时记得类型转换</returns>
        public static object ExecuteScalar(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            SqlCommand cmd = new SqlCommand();
            PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
            object val = cmd.ExecuteScalar();
            cmd.Parameters.Clear();
            return val;
        }

        /// <summary>
        /// 在缓存中添加参数数组
        /// </summary>
        /// <param name="cacheKey">参数的Key</param>
        /// <param name="commandParameters">参数数组</param>
        public static void CacheParameters(string cacheKey, params SqlParameter[] commandParameters)
        {
            parmCache[cacheKey] = commandParameters;
        }

        /// <summary>
        /// 提取缓存的参数数组
        /// </summary>
        /// <param name="cacheKey">查找缓存的key</param>
        /// <returns>返回被缓存的参数数组</returns>
        public static SqlParameter[] GetCachedParameters(string cacheKey)
        {
            SqlParameter[] cachedParms = (SqlParameter[])parmCache[cacheKey];
            if (cachedParms == null)
                return null;
            SqlParameter[] clonedParms = new SqlParameter[cachedParms.Length];

            for (int i = 0, j = cachedParms.Length; i < j; i++)
                clonedParms[i] = (SqlParameter)((ICloneable)cachedParms[i]).Clone();
            return clonedParms;
        }

        /// <summary>
        /// 提供一个SqlCommand对象的设置
        /// </summary>
        /// <param name="cmd">SqlCommand对象</param>
        /// <param name="conn">SqlConnection 对象</param>
        /// <param name="trans">SqlTransaction 对象</param>
        /// <param name="cmdType">CommandType 如存贮过程，T-SQL</param>
        /// <param name="cmdText">存贮过程名或查询串</param>
        /// <param name="cmdParms">命令中用到的参数集</param>
        private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)
        {
            if (conn.State != ConnectionState.Open)
                conn.Open();
            cmd.Connection = conn;
            cmd.CommandText = cmdText;
            if (trans != null)
                cmd.Transaction = trans;
            cmd.CommandType = cmdType;
            if (cmdParms != null)
            {
                foreach (SqlParameter parm in cmdParms)
                    cmd.Parameters.Add(parm);
            }
        }

        /// <summary>
        /// 执行sql语句（带参数）到DataSet
        /// 作者：陈慧君
        /// </summary>
        /// <param name="connString"></param>
        /// <param name="cmdType"></param>
        /// <param name="cmdText"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public static DataSet ExecuteQueryToSet(string connString, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
        {
            DataSet mySet = new DataSet();
            SqlCommand cmd = new SqlCommand();
            using (SqlConnection myConnection = new SqlConnection(connString))
            {
                PrepareCommand(cmd, myConnection, null, cmdType, cmdText, cmdParms);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(mySet);
                myConnection.Close();
            }
            return mySet;
        }
        /// <summary>
        /// 执行sql语句（带参数）到DataSet，
        /// 此为带连接和带事务的操作，慎用！
        /// 作者：陈慧君
        /// </summary>
        /// <param name="theConnection"></param>
        /// <param name="theTransaction"></param>
        /// <param name="cmdType"></param>
        /// <param name="cmdText"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public static DataSet ExecuteQueryToSet(SqlConnection theConnection, SqlTransaction theTransaction, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
        {
            DataSet mySet = new DataSet();
            SqlCommand cmd = new SqlCommand();
            PrepareCommand(cmd, theConnection, null, cmdType, cmdText, cmdParms);
            if (theTransaction.Connection != theConnection)
            {
                throw new Exception("传入的连接和事务不属于同一个数据连接的范围！");
            }
            cmd.Transaction = theTransaction;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(mySet);
            return mySet;
        }

        /// <summary>
        /// 直接执行sql语句（可带参数）到DataTable
        /// 作者：陈慧君
        /// </summary>
        /// <param name="connString"></param>
        /// <param name="cmdType"></param>
        /// <param name="cmdText"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public static DataTable ExecuteQueryToTable(string connString, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
        {
            DataTable myTable = new DataTable();
            SqlCommand cmd = new SqlCommand();
            using (SqlConnection myConnection = new SqlConnection(connString))
            {
                PrepareCommand(cmd, myConnection, null, cmdType, cmdText, cmdParms);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(myTable);
                myConnection.Close();
                cmd.Parameters.Clear();
            }
            return myTable;
        }
        /// <summary>
        /// 直接执行sql语句（可带参数）到DataTable
        /// 此为带连接和带事务的操作，慎用！
        /// 作者：陈慧君
        /// </summary>
        /// <param name="theConnection"></param>
        /// <param name="theTransaction"></param>
        /// <param name="cmdType"></param>
        /// <param name="cmdText"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public static DataTable ExecuteQueryToTable(SqlConnection theConnection, SqlTransaction theTransaction, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
        {
            DataTable myTable = new DataTable();
            SqlCommand cmd = new SqlCommand();
            PrepareCommand(cmd, theConnection, null, cmdType, cmdText, cmdParms);
            if (theTransaction.Connection != theConnection)
            {
                throw new Exception("传入的连接和事务不属于同一个数据连接的范围！");
            }
            cmd.Transaction = theTransaction;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(myTable);
            return myTable;
        }
        /// <summary>
        /// 使用DataSet中的数据进行对数据源的相应表的数据进行更新
        /// </summary>
        /// <param name="connString">数据库联接字符串</param>
        /// <param name="selectCmd">其中结果集的相应的选择语句</param>
        /// <param name="srcTable">相应的数据源中的源表的表名</param>
        /// <param name="updateDataSet">用于更新数据的数据集DataSet</param>
        /// <returns></returns>
        public static bool UpdateByDataSet(string connString, string selectCmd, string srcTable, DataSet updateDataSet)
        {
            bool sucess = false;
            if (updateDataSet.HasChanges())
            {
                using (SqlConnection myConnection = new SqlConnection(connString))
                {
                    myConnection.Open();
                    SqlDataAdapter da = new SqlDataAdapter(selectCmd, myConnection);
                    SqlCommandBuilder cb = new SqlCommandBuilder(da);
                    try
                    {
                        da.Update(updateDataSet, srcTable);
                        updateDataSet.AcceptChanges();
                        sucess = true;
                    }
                    catch (Exception ex)
                    {
                        updateDataSet.RejectChanges();
                        throw ex;
                    }
                    finally
                    {
                        myConnection.Close();
                    }
                }
                return sucess;
            }
            else
                return sucess;
        }


        public static bool UpdateByDataSet(SqlConnection sqlconnect, string sqlstr, string tablename, DataSet ds, SqlTransaction sqltrans)
        {
            bool sucess = false;
            try
            {

                //using (SqlConnection myConnection = new SqlConnection(connString))
                //{
                SqlDataAdapter adapter = new SqlDataAdapter(sqlstr, sqlconnect);
                SqlCommandBuilder cmdbuilder = new SqlCommandBuilder(adapter);

                //创建sqldataadapter 对像的command对像，并将连接对像及事务对像绑定到command对像上

                adapter.DeleteCommand = new SqlCommand("", sqlconnect, sqltrans);
                adapter.InsertCommand = new SqlCommand("", sqlconnect, sqltrans);
                adapter.UpdateCommand = new SqlCommand("", sqlconnect, sqltrans);
                adapter.SelectCommand = new SqlCommand(sqlstr, sqlconnect, sqltrans);

                //使用getdeletecommand将相对应的sqlcommand对像传入

                adapter.DeleteCommand = cmdbuilder.GetDeleteCommand();
                adapter.InsertCommand = cmdbuilder.GetInsertCommand();
                adapter.UpdateCommand = cmdbuilder.GetUpdateCommand();
                //cmdbuilder.refreshschema();
                int val = adapter.Update(ds, tablename);
                ds.Tables[tablename].AcceptChanges();
                sucess = true;
                return sucess;
                //}
            }
            catch (Exception ex)
            {
                throw ex;

            }

        }


        public static bool UpdateByDataSet(SqlConnection sqlconnect, string sqlstr, string tablename, string UpdateSql, SqlParameter[] srcSqlParameter, DataSet ds, SqlTransaction sqltrans)
        {
            bool sucess = false;
            try
            {

                SqlDataAdapter adapter = new SqlDataAdapter(sqlstr, sqlconnect);
                SqlCommandBuilder cmdbuilder = new SqlCommandBuilder(adapter);

                #region 处理update语句
                SqlCommand UpdateCmd;
                UpdateCmd = new SqlCommand(UpdateSql, sqlconnect, sqltrans);
                int i = 0;
                foreach (SqlParameter mSqlParameter in srcSqlParameter)
                {

                    UpdateCmd.Parameters.Add(mSqlParameter);
                    UpdateCmd.Parameters[i].SourceColumn = mSqlParameter.ParameterName.Substring(1);

                    i = i + 1;
                }
                adapter.UpdateCommand = UpdateCmd;
                #endregion


                //创建sqldataadapter 对像的command对像，并将连接对像及事务对像绑定到command对像上

                adapter.DeleteCommand = new SqlCommand("", sqlconnect, sqltrans);
                adapter.InsertCommand = new SqlCommand("", sqlconnect, sqltrans);
                //adapter.UpdateCommand = new SqlCommand("", sqlconnect, sqltrans);
                adapter.SelectCommand = new SqlCommand(sqlstr, sqlconnect, sqltrans);

                //使用getdeletecommand将相对应的sqlcommand对像传入

                adapter.DeleteCommand = cmdbuilder.GetDeleteCommand();
                adapter.InsertCommand = cmdbuilder.GetInsertCommand();
                //adapter.UpdateCommand = cmdbuilder.GetUpdateCommand();
                adapter.UpdateCommand = UpdateCmd;

                int val = adapter.Update(ds, tablename);
                ds.Tables[tablename].AcceptChanges();
                sucess = true;
                return sucess;
            }
            catch (Exception ex)
            {
                throw ex;

            }

        }


    }

    ///<summary>
    ///版权所有：css
    ///内容摘要：数据库操作类CssSqlHelper。
    ///完成日期：2008年7月
    ///版本：V 1.0
    ///作者：陈慧君
    ///
    ///修改记录1：
    ///修改日期：
    ///版本号：
    ///修改人：
    ///修改内容：
    ///</summary>
    public class CssSQLHelper
    {
        /// <summary>
        /// 使用连接字符串，执行一个SqlCommand命令（没有记录返回）
        /// 使用提供的参数集.
        /// </summary>
        /// <remarks>
        /// 示例:  
        ///  int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="connectionString">一个有效的SqlConnection连接串</param>
        /// <param name="cmdType">命令类型CommandType(stored procedure, text, etc.)</param>
        /// <param name="cmdText">存贮过程名称或是一个T-SQL语句串</param>
        /// <param name="commandParameters">执行命令的参数集</param>
        /// <returns>受此命令影响的行数</returns>
        public static int CssExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            return SqlHelper.ExecuteNonQuery(connectionString, cmdType, cmdText, commandParameters);
        }

        /// <summary>
        /// 在一个存在的连接上执行数据库的命令操作
        /// 使用提供的参数集.
        /// </summary>
        /// <remarks>
        /// e.g.:  
        ///  int result = ExecuteNonQuery(connection, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="connection">一个存在的数据库连接对象</param>
        /// <param name="cmdType">命令类型CommandType (stored procedure, text, etc.)</param>
        /// <param name="cmdText">存贮过程名称或是一个T-SQL语句串</param>
        /// <param name="commandParameters">执行命令的参数集</param>
        /// <returns>受此命令影响的行数</returns>
        public static int CssExecuteNonQuery(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            return SqlHelper.ExecuteNonQuery(connection, cmdType, cmdText, commandParameters);
        }

        /// <summary>
        /// 在一个事务的连接上执行数据库的命令操作
        /// 使用提供的参数集.
        /// </summary>
        /// <remarks>
        /// e.g.:  
        ///  int result = ExecuteNonQuery(trans, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="trans">一个存在的事务</param>
        /// <param name="cmdType">命令类型CommandType (stored procedure, text, etc.)</param>
        /// <param name="cmdText">存贮过程名称或是一个T-SQL语句串</param>
        /// <param name="commandParameters">执行命令的参数集</param>
        /// <returns>受此命令影响的行数</returns>
        public static int CssExecuteNonQuery(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            return SqlHelper.ExecuteNonQuery(trans, cmdType, cmdText, commandParameters);
        }

        /// <summary>
        /// 在一个连接串上执行一个命令，返回一个SqlDataReader对象
        /// 使用提供的参数.
        /// </summary>
        /// <remarks>
        /// e.g.:  
        ///  SqlDataReader r = ExecuteReader(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="connectionString">一个有效的SqlConnection连接串</param>
        /// <param name="cmdType">命令类型CommandType(stored procedure, text, etc.)</param>
        /// <param name="cmdText">存贮过程名称或是一个T-SQL语句串</param>
        /// <param name="commandParameters">执行命令的参数集</param>
        /// <returns>一个结果集对象SqlDataReader</returns>
        public static SqlDataReader CssExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            return SqlHelper.ExecuteReader(connectionString, cmdType, cmdText, commandParameters);
        }

        /// <summary>
        /// 在一个连接串上执行一个命令，返回表中第一行，第一列的值
        /// 使用提供的参数.
        /// </summary>
        /// <remarks>
        /// e.g.:  
        ///  Object obj = ExecuteScalar(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="connectionString">一个有效的SqlConnection连接串</param>
        /// <param name="cmdType">命令类型CommandType(stored procedure, text, etc.)</param>
        /// <param name="cmdText">存贮过程名称或是一个T-SQL语句串</param>
        /// <param name="commandParameters">执行命令的参数集</param>        /// <returns>返回的对象，在使用时记得类型转换</returns>
        public static object CssExecuteScalar(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            return SqlHelper.ExecuteScalar(connectionString, cmdType, cmdText, commandParameters);
        }

        /// <summary>
        /// 在一个连接上执行一个命令，返回表中第一行，第一列的值
        /// 使用提供的参数.
        /// </summary>
        /// <remarks>
        /// e.g.:  
        ///  Object obj = ExecuteScalar(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="connection">一个有效的SqlConnection连接</param>
        /// <param name="cmdType">命令类型CommandType(stored procedure, text, etc.)</param>
        /// <param name="cmdText">存贮过程名称或是一个T-SQL语句串</param>
        /// <param name="commandParameters">执行命令的参数集</param>        /// <returns>返回的对象，在使用时记得类型转换</returns>
        public static object CssExecuteScalar(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            return SqlHelper.ExecuteScalar(connection, cmdType, cmdText, commandParameters);
        }

        /// <summary>
        /// 执行sql语句（带参数）到DataSet
        /// 作者：陈慧君
        /// </summary>
        /// <param name="connString">一个有效的SqlConnection连接串</param>
        /// <param name="cmdType">命令类型CommandType(stored procedure, text, etc.)</param>
        /// <param name="cmdText">存贮过程名称或是一个T-SQL语句串</param>
        /// <param name="cmdParms">执行命令的参数集</param>
        /// <returns>一个结果集对象DataSet</returns>
        public static DataSet CssExecuteQueryToDataSet(string connString, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
        {
            return SqlHelper.ExecuteQueryToSet(connString, cmdType, cmdText, cmdParms);
        }

        /// <summary>
        /// 执行sql语句（带参数）到DataSet
        /// 带有连接和事务的操作，慎用！
        /// 注意事务的Commit和Rollback
        /// 注意连接的关闭（close）
        /// 作者：陈慧君
        /// </summary>
        /// <param name="myConnection">连接</param>
        /// <param name="myTransaction">事务</param>
        /// <param name="cmdType">命令类型CommandType(stored procedure, text, etc.)</param>
        /// <param name="cmdText">存贮过程名称或是一个T-SQL语句串</param>
        /// <param name="cmdParms">执行命令的参数集</param>
        /// <returns>一个结果集对象DataTable</returns>
        public static DataSet CssExecuteQueryToDataSet(SqlConnection myConnection, SqlTransaction myTransaction, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
        {
            return SqlHelper.ExecuteQueryToSet(myConnection, myTransaction, cmdType, cmdText, cmdParms);
        }

        /// <summary>
        /// 直接执行sql语句（可带参数）到DataTable
        /// 作者：陈慧君
        /// </summary>
        /// <param name="connString">一个有效的SqlConnection连接串</param>
        /// <param name="cmdType">命令类型CommandType(stored procedure, text, etc.)</param>
        /// <param name="cmdText">存贮过程名称或是一个T-SQL语句串</param>
        /// <param name="cmdParms">执行命令的参数集</param>
        /// <returns>一个结果集对象DataTable</returns>
        public static DataTable CssExecuteQueryToDataTable(string connString, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
        {
            return SqlHelper.ExecuteQueryToTable(connString, cmdType, cmdText, cmdParms);
        }

        /// <summary>
        /// 直接执行sql语句（可带参数）到DataTable
        /// 带有连接和事务的操作，慎用！
        /// 注意事务的Commit和Rollback
        /// 注意连接的关闭（close）
        /// 作者：陈慧君
        /// </summary>
        /// <param name="myConnection">连接</param>
        /// <param name="myTransaction">事务</param>
        /// <param name="cmdType">命令类型CommandType(stored procedure, text, etc.)</param>
        /// <param name="cmdText">存贮过程名称或是一个T-SQL语句串</param>
        /// <param name="cmdParms">执行命令的参数集</param>
        /// <returns>一个结果集对象DataTable</returns>
        public static DataTable CssExecuteQueryToDataTable(SqlConnection myConnection, SqlTransaction myTransaction, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
        {
            return SqlHelper.ExecuteQueryToTable(myConnection, myTransaction, cmdType, cmdText, cmdParms);
        }
        /// <summary>
        /// 使用DataSet中的数据进行对数据源的相应表的数据进行更新
        /// </summary>
        /// <param name="connString">数据库联接字符串</param>
        /// <param name="selectCmd">其中结果集的相应的选择语句</param>
        /// <param name="srcTable">相应的数据源中的源表的表名</param>
        /// <param name="updateDataSet">用于更新数据的数据集DataSet</param>
        /// <returns>更新是否成功</returns>
        public static bool CssUpdateByDataSet(string connString, string selectCmd, string srcTable, DataSet updateDataSet)
        {
            return SqlHelper.UpdateByDataSet(connString, selectCmd, srcTable, updateDataSet);
        }

        /// <summary>
        /// 使用DataSet中的数据进行对数据源的相应表的数据进行更新,使用到SqlTransaction
        /// </summary>
        /// <param name="sqlconnect">数据库联接字符串</param>
        /// <param name="selectCmd">其中结果集的相应的选择语句</param>
        /// <param name="srcTable">相应的数据源中的源表的表名</param>
        /// <param name="updateDataSet">用于更新数据的数据集DataSet</param>
        /// <param name="pTr">数据库连接事务</param>
        /// <returns>更新是否成功</returns>
        public static bool CssUpdateByDataSet(SqlConnection sqlconnect, string selectCmd, string srcTable, DataSet updateDataSet, SqlTransaction pTr)
        {
            return SqlHelper.UpdateByDataSet(sqlconnect, selectCmd, srcTable, updateDataSet, pTr);
        }

        public static bool CssUpdateByDataSet(SqlConnection sqlconnect, string selectCmd, string srcTable, string UpdateCmd, SqlParameter[] srcSqlParameter, DataSet updateDataSet, SqlTransaction pTr)
        {
            return SqlHelper.UpdateByDataSet(sqlconnect, selectCmd, srcTable, UpdateCmd, srcSqlParameter, updateDataSet, pTr);
        }

    }
}
